require 'net/http'
require 'rubygems'
require 'xmlsimple'

class Restaurant < ActiveRecord::Base
	APIKEY = "3b7c6b1299c80cd69bbe940d99077dc8"
	TARGET = 'local'
	def self.search(q)
	  query = URI.escape(q, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
	  url = 'http://openapi.naver.com/search?key='+APIKEY+'&soft=vote&target='+TARGET+'&query='+ query;
  
	  xml_data = Net::HTTP.get_response(URI.parse(url)).body		
	  
	  data = XmlSimple.xml_in(xml_data)
	  
	  return data['channel']
	end	
end
